#define DEBUG
#include <cstdio>
#include <cmath>

using namespace std;

typedef long long ll;

const int maxn=100000, maxm=100000;

class Set {
public:
  int fa[maxn+1], last[maxn+1];
  ll v[maxn+1];
  bool flag[maxn+1];

  int getFa(int o) {
    if (o!=fa[o]) {
      v[fa[o]] += v[o], v[o]=0;
      flag[fa[o]] |= flag[o];
      fa[o] = getFa(fa[o]);
    }
    return fa[o];
  }

  void merge(int x, int y) {
    x = getFa(x), y=getFa(y);
    if (x!=y) {
      fa[y] = x;
      if (last[x] && last[y]) {
        merge(last[x], last[y]);
      }
      if (!last[x]) {
        last[x] = last[y];
      }
    }
  }
};

class Graph {
public:
  Set s;
  int n, m, ind[maxn+1], to[2*maxm+1], link[2*maxm+1];
  bool vis[maxn+1];

  void init(int n) {
    this->n = n;
    m = 0;
    for (int i=1; i<=n; i++) {
      ind[i] = 0;
      vis[i] = false;
    }
  }
  
  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  void connect() {
    for (int i=1; i<=n; i++) {
      int x=s.getFa(i);
      for (int j=ind[i]; j; j=link[j]) {
        if (s.getFa(to[j])==s.getFa(x)) {
          s.flag[x] = true;
        }
        if (s.last[x]) {
          s.merge(s.last[x], to[j]);
        }
        s.last[x] = to[j];
      }
    }
  }

  bool check() {
    for (int i=1; i<=n; i++) {
      s.getFa(i);
    }
    for (int i=1; i<=n; i++) {
      int x=s.getFa(i), y;
      if (!vis[x]) {
        for (int j=ind[i]; j; j=link[j]) {
          y=s.getFa(to[j]);
          if (!vis[y] && x!=y) {
            if (s.flag[x]||s.flag[y]) {
              if (abs(s.v[x]%2)!=abs(s.v[y]%2)) {
                return false;
              }
            } else {
              if (s.v[x]!=s.v[y]) {
                return false;
              }
            }
            vis[x]=true, vis[y]=true;
            break;
          }
        }
      }
    }
    for (int i=1; i<=n; i++) {
      if (s.getFa(i)==i && !vis[i]) {
        if (s.flag[i]) {
          if (s.v[i]%2) {
            return false;
          }
        } else {
          if (s.v[i]) {
            return false;
          }
        }
      }
    }
    return true;
  }
};

int main() {
  freopen("sequence.in", "r", stdin);
  freopen("sequence.out", "w", stdout);

  static ll a[maxn+1], b[maxn+1];
  int t;
  scanf("%d", &t);
  for (int ti=1; ti<=t; ti++) {
    static Graph g;
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i=1; i<=n; i++) {
      scanf("%lld", a+i);
    }
    g.init(n);

    for (int i=1; i<=n; i++) {
      scanf("%lld", b+i);
      g.s.fa[i] = i, g.s.v[i] = b[i]-a[i], g.s.flag[i]=false, g.s.last[i]=0;
    }

    for (int i=1; i<=m; i++) {
      int t, a, b;
      scanf("%d %d %d", &t, &a, &b);
      if (t==1) {
        g.addSide(a, b);
        g.addSide(b, a);
      } else {
        g.s.merge(a, b);
      }
    }

    g.connect();

    if (g.check()) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
